using AutoMapper;
using ChikovMF.Application.Common.Mappings;
using ChikovMF.Application.Features.Projects.CreateProject;
using ChikovMF.Application.Features.Projects.EditProject;
using ChikovMF.Application.Features.Projects.Shared;
using ChikovMF.Entities;
using static ChikovMF.Application.Features.Projects.Shared.ProjectModel;

namespace ChikovMF.WebAPI.Models.Projects;

public class ProjectDto : IMapWith<ProjectModel>
{
    public string Name { get; set; } = null!;
    public string Description { get; set; } = null!;
    public string Content { get; set; } = null!;
    public ICollection<ProjectTagDto>? Tags { get; set; }
    public ICollection<ProjectLinkDto>? Links { get; set; }

    public void Mapping(Profile profile)
    {
        profile.CreateMap<ProjectDto, CreateProjectCommand>()
            .ForMember(command => command.Tags,
                opt => opt.MapFrom(dto => dto.Tags))
            .ForMember(command => command.Links,
                opt => opt.MapFrom(dto => dto.Links));

        profile.CreateMap<ProjectDto, EditProjectCommand>()
            .ForMember(command => command.Tags,
                opt => opt.MapFrom(dto => dto.Tags))
            .ForMember(command => command.Links,
                opt => opt.MapFrom(dto => dto.Links));
    }

    public class ProjectTagDto : IMapWith<ProjectTag>
    {
        public int Order { get; set; }
        public Guid TagId { get; set; }

        public void Mapping(Profile profile)
        {
            profile.CreateMap<ProjectTagDto, ProjectTagModel>();
        }
    }

    public class ProjectLinkDto : IMapWith<Link>
    {
        public string Name { get; set; } = null!;
        public Uri Url { get; set; } = null!;

        public void Mapping(Profile profile)
        {
            profile.CreateMap<ProjectLinkDto, ProjectLinkModel>();
        }
    }
}
